<template>
  <div class="container">
      <div class="weui-cell">
          <div  class="weui-cell__bd"></div>
          <div  class="weui-cell__ft">
              <report :info="info" type="2" model="1"></report>
          </div>
      </div>
      <div class="className">
        {{info.title}}
      </div>
      <div class="originator weui-cell" >
        <div class="weui-cell__hd">
             <avatar :avatar="info.user.avatar" :Level="info.user.partner_level" :userId="info.user.id" :isAuth="info.user.is_auth" :isPartner="info.user.is_partner" v-if="info.user"></avatar>
        </div>
        <div class="weui-cell__bd">
            <div class="nickname" v-if="info.user">
              {{info.user.nickname}}  <van-tag color="#E9B55E" v-if="info.source==1">自创</van-tag > <van-tag color="#E9B55E" v-else>转载</van-tag>
            </div>
            <div class="time">{{info.created_at}}  
              <span v-if="info.user.is_auth==3&&info.user.role==1"> | 家长</span>
              <span v-if="info.user.is_auth==3&&info.user.role==2"> | 老师</span>
              <span v-if="info.user.is_auth==3&&info.user.role==3"> | 教育公司</span>
              <span v-if="info.user.is_auth==3&&info.user.role==4"> | 教育媒体</span>
              <span v-if="info.user.is_auth==3&&info.user.role==5"> | 其他</span>
              <span v-if="info.user.is_auth==3&&info.user.role==6"> | 本地学校</span>
            </div> 
        </div>
        <div class="weui-cell__ft">
            <Follow :info="info" :userId="info.user.id" ></Follow>
        </div>
      </div>
      <div class="content">
         <wxParse :content="info.content" v-if="info.content"/>
      </div>
      <comment :comment="info" :role="isz==1?'11':'17'" @click="change" :listCom="list"></comment>
  </div>
</template>

<script>
import wxParse from 'mpvue-wxparse'
import comment from "@/components/comment";
import report  from "@/components/report"
import Follow  from "@/components/follow"
import avatar from "@/components/avatar"
import {show} from "@/api/index"

import {showComment} from "@/api/operate.js"
import {zanComment} from "@/api/operate.js"
export default {
  components: {
      comment,
      Follow,
      report,
      avatar,
      wxParse
  },

  data () {
    return {
      info:{},
      zan:"",
      isz:"",
      collect:{},
      keType:"",
      userId:0,
      list:[],
      load:false,
      columnid:"",
      currentpage:1
    }
  },
  methods:{
     toInfo(e){
        let url=e.currentTarget.dataset.url;
        mpvue.navigateTo({url})
     },
     getINfo(){
       let data={};
       data.id=this.columnid;
       data.uid=this.userId;
       data.type=this.keType;
       show(data).then(res=>{
          console.log(res)
          this.info=res.data
       })
     },
     changeValue(item){
        let guan=item.guan;
        item.guan=!guan;
     },
     change(data){
       console.log(data)
        this.info=data.comment
     },
     bian(item){
       console.log(item.zan.is_action)
       let zan=item.zan.is_action;
       item.zan.is_action=!zan
       this.info=item
     },
     
    getComment(){
       let data={};
       data.type=this.keType;
       data.id=this.columnid
       data.user_id=this.userId;
         
      showComment(data).then(res=>{
        console.log(res)
        if(res.code==200){
          this.queS=false
          let last_page=res.data.total_page;
          if(this.currentpage==1){
            this.list=res.data.data
          }else{
            this.list=this.list.concat(res.data.data);
          }
          console.log(this.list)
          if (last_page > this.currentpage){
              this.load=true
          }else{
              this.load=false
          }
        }else{
           this.list=[]
           this.queS=true
        }
          
      },err=>{
          this.queS=true
      }).catch(err=>{
          this.queS=true
      })
    },
  },
  created () { 
  },
  onShow(){
    this.getINfo()
    this.getComment()
    
  },
  onLoad(options){
     Object.assign(this.$data, this.$options.data())
     this.columnid=options.id;
     this.keType=options.keType;
     wx.getStorageSync("user_info")?this.userId=wx.getStorageSync("user_info").id:'';
     this.isz=options.isz;
     if(this.isz==1){
         wx.setNavigationBarTitle({
           title: '专栏',
           success: (result) => {
             
           },
           fail: () => {},
           complete: () => {}
         });
           
     }else{
         wx.setNavigationBarTitle({
           title: '资讯',
           success: (result) => {
             
           },
           fail: () => {},
           complete: () => {}
         });
     }
  },
  onUnload(){
     console.log("我已经离开了！");
     
  },
  onReachBottom(){
    if(this.load){
       this.currentpage++
       this.getComment()
    }
  },

}
</script>
<style>

@import url("~mpvue-wxparse/src/wxParse.css");
.classify .nav .nav-item {
  width: 25%;
}
</style>
<style scoped lang="scss">
    .className{
      font-size:15px;
      padding: 7px 15px;
      font-weight:bold;
      color:rgba(51,51,51,1);
      line-height:18px;
      padding-top: 0;
    }
    .nickname{
      font-size:14px;
      font-weight:bold;
      color:rgba(26,132,251,1);
      line-height:18px;
    }
    .content{
      padding: 15px 10px;
      font-size:14px;
      font-weight:500;
      color:rgba(51,51,51,1);
      line-height:21px;
    }
</style>
